<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>检测html5Storage</title>
</head>
<body>
    <button onclick="clickCounter()">click me</button>
    <div id="result"></div>
    <p>点击该按钮查看计数器的增加。</p>
    <p>关闭浏览器选项卡(或窗口),重新打开此页面,计数器将继续计数(不是重置)。</p>
<script>
    function clickCounter() {
        if(typeof(Storage)!=="undefined") {

            if(localStorage.clickcount){
                localStorage.clickcount = Number(localStorage.clickcount) + 1;
                console.log("点击第二次以及第二次之后点击");
            }else {
                localStorage.clickcount = 1;
                console.log("点击第一次");
            }
            document.getElementById("result").innerHTML = "已经点击了" + localStorage.clickcount + "次";

            //  if (localStorage.clickcount) {
            //      localStorage.clickcount=Number(localStorage.clickcount)+1;
            //  }
            //  else {
            //      localStorage.clickcount=1;
            //  }
            //  document.getElementById("result").innerHTML=" 你已经点击了按钮 " + localStorage.clickcount + " 次 ";


        } else {

            console.log("不支持");
        }
    }


</script>
</body>
</html>
